package io.gitee.zhucan123.core.infrastructure.util;

import org.springframework.cglib.beans.BeanMap;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * @author: zhuCan
 * @date: 2019/12/24 14:02
 * @description:
 */

public class RestMultiData {

  private RestMultiData() {
  }

  public static MultiValueMap<String, Object> multiValueMap(Object req) {
    MultiValueMap<String, Object> reqMap = new LinkedMultiValueMap<>();
    BeanMap beanMap = BeanMap.create(req);
    beanMap.keySet().stream().filter(y -> beanMap.get(y) != null).forEach(key -> reqMap.add(key.toString(), beanMap.get(key) instanceof String ? ((String) beanMap.get(key)).trim() : beanMap.get(key)));

    return reqMap;
  }
}
